package com.example.hm_dtfkz.ui.activity;


import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.constraintlayout.widget.ConstraintLayout;

import com.alibaba.android.arouter.launcher.ARouter;
import com.android.base.util.ToastUtil;
import com.android.base.util.http.RxhttpUtil;
import com.dq.ad.ADUtils;
import com.dq.ad.AdManager;
import com.dq.ad.ui.CSJSplashActivity;
import com.example.hm_dtfkz.BuildConfig;
import com.example.hm_dtfkz.MainActivity;
import com.example.hm_dtfkz.R;
import com.example.hm_dtfkz.app.QuestionsApp;
import com.example.hm_dtfkz.config.AnswerAdConfig;
import com.example.hm_dtfkz.config.AnswerDataConfig;
import com.example.hm_dtfkz.config.AppConfig;
import com.example.hm_dtfkz.config.LoginConfig;
import com.example.hm_dtfkz.litepal.WXLogin;
import com.example.hm_dtfkz.ui.dialog.DialogBanned;
import com.example.hm_dtfkz.ui.dialog.DialogPolicy;
import com.example.hm_dtfkz.util.AppUtils;
import com.example.hm_dtfkz.util.DQLog;
import com.example.hm_dtfkz.util.DetectionUtil;
import com.example.hm_dtfkz.util.FMAgentManger;
import com.example.hm_dtfkz.util.FastJsonUtil;
import com.example.hm_dtfkz.util.JsonUtil;
import com.example.hm_dtfkz.util.Mmkv;
import com.example.hm_dtfkz.util.RootCheck;
import com.example.hm_dtfkz.util.SystemUtil;
import com.dq.ad.utils.UIUtils;
import com.google.gson.Gson;
import com.hx.update.UpdateInfo;
import com.kc.openset.ad.listener.OSETSplashListener;
import com.kc.openset.ad.splash.OSETSplash;
import com.kc.openset.config.OSETSDK;
import com.kc.openset.listener.OSETInitListener;
import com.snail.antifake.jni.EmulatorDetectUtil;
import com.tencent.mm.opensdk.utils.Log;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

import rxhttp.wrapper.utils.LogUtil;


/**
 * FileName: SplashActivity
 * Author: admin
 * Date: 2021/10/27 15:38
 * Description:
 */
public class SplashActivity extends AppCompatActivity {

    private volatile boolean isStart = false;
    private FrameLayout flAd;
    private ConstraintLayout clMask;
    private TextView tvAppName;
    private ImageView imgLogo;
    private AppCompatTextView tvTipsTitle;
    private AppCompatTextView tvTipsContent;

    private String keyFrom;

    private final ActivityResultLauncher<String> requestPermission1 = registerForActivityResult(new ActivityResultContracts.RequestPermission(), new ActivityResultCallback<Boolean>() {
        @Override
        public void onActivityResult(Boolean result) {
            requestPermission2();
        }
    });

    private final ActivityResultLauncher<String[]> requestPermission2 = registerForActivityResult(new ActivityResultContracts.RequestMultiplePermissions(), new ActivityResultCallback<Map<String, Boolean>>() {
        @Override
        public void onActivityResult(Map<String, Boolean> result) {
            initTongdunSDK();
        }
    });

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            getWindow().setStatusBarColor(Color.TRANSPARENT);
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
            WindowManager.LayoutParams lp = getWindow().getAttributes();
            lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
            getWindow().setAttributes(lp);
        }

        setContentView(R.layout.activity_splash);
        keyFrom = getIntent().getStringExtra("key_from");
        if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {
            finish();
            return;
        }
//        boolean vpn = DetectionUtil.isVPN(this);
//        DQLog.e("vpn: " + vpn);
//        boolean wifiProxy = DetectionUtil.isWifiProxy();
//        DQLog.e("wifiProxy: " + wifiProxy);

        getChannelString(this.getApplicationContext());

        initView();

    }

    private void getChannelString(Context context) {
        try {
            PackageManager packageManager = context.getPackageManager();
            if (packageManager != null) {
                ApplicationInfo applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
                if (applicationInfo.metaData != null) {
                    String hxChTypeName = Objects.requireNonNull(applicationInfo.metaData.get("HX_CH_TYPE_NAME")).toString();
                    String hxChTypeId = Objects.requireNonNull(applicationInfo.metaData.get("HX_CH_TYPE_ID")).toString();
                    DQLog.e("hxChTypeName: " + hxChTypeName + ", hxChTypeId: " + hxChTypeId);
//                    String chId = context.getString(R.string.CH_ID);
                    String chId = " context.getString(R.string.CH_ID)";
                    if (hxChTypeName.contentEquals("share") || hxChTypeName.contentEquals("push")) {
                        chId = chId + "_" + hxChTypeName;
                    } else if (hxChTypeName.contentEquals("juliang")) {

                    } else {
                        chId = chId + "_SY_" + hxChTypeName;
                    }
                    AppConfig.CH_ID = chId;
                    AppConfig.CH_TYPE_ID = Integer.parseInt(hxChTypeId);
                    DQLog.e("ch_id: " + AppConfig.CH_ID + ", ch_type_id: " + AppConfig.CH_TYPE_ID);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void initView() {
//        DQLog.e("应用包名：" + SystemUtil.getPackageName(this));
        flAd = findViewById(R.id.layoutAd);

        clMask = findViewById(R.id.cl_mask);
        tvAppName = findViewById(R.id.tvAppName);
        tvTipsTitle = findViewById(R.id.tv_tips_title);
        tvTipsContent = findViewById(R.id.tv_tips_content);

        clMask.setVisibility(View.GONE);
        tvAppName.setText(AppUtils.getAppName(this));
        TextView tvLoading = findViewById(R.id.tvLoading);

//        JumpingBeans.with(tvLoading)
//                .appendJumpingDots()
//                .setLoopDuration(1000)
//                .build();

        if (!AppConfig.getAgreed()) {//如果没有授权隐私政策，则显示
            new DialogPolicy(this, new DialogPolicy.OnPolicyListener() {
                @Override
                public void onPolicy() {
                    UserServiceAgreementActivity.startAct(SplashActivity.this, UserServiceAgreementActivity.TYPE_PRIVACY);
                }

                @Override
                public void onUser() {
                    UserServiceAgreementActivity.startAct(SplashActivity.this, UserServiceAgreementActivity.TYPE_USER);
                }

                @Override
                public void onCancel() {
                    finish();
                }

                @Override
                public void onAgreed() {
//                    AdManager.getInstance().initSDK(SplashActivity.this,"5434240","","",false,false,false);
                    AppConfig.setAgreed(true);
                    AppConfig.setGameSound(true);
                    AppConfig.setBackMusic(true);
                    initData();
                    initAdSDK();
                    OSETSDK.getInstance().init(QuestionsApp.questionsApp, AppUtils.getAPPId(), new OSETInitListener() {
                        @Override
                        public void onError(String s) {
                            ToastUtil.showShortToast(SplashActivity.this, s);
                        }

                        @Override
                        public void onSuccess() {//初始化成功 调用广告
                            OSETSplash.getInstance()
                                    .setUserId(LoginConfig.getUserOpenId())
                                    .show(SplashActivity.this, flAd, AppUtils.getADID(4), new OSETSplashListener() {
                                        @Override
                                        public void onClick() {
                                            ToastUtil.showShortToast(getApplicationContext(), "点击");
                                        }

                                        @Override
                                        public void onClose() {
                                            ToastUtil.showShortToast(getApplicationContext(), "关闭");
                                        }

                                        @Override
                                        public void onShow() {

                                        }

                                        @Override
                                        public void onError(String s, String s1) {
//                        ToastUtil.showShortToast(getApplicationContext(),"onError"+s1);
                                        }
                                    });
                        }
                    });
                }
            }).show();
        } else {
            OSETSDK.getInstance().init(QuestionsApp.questionsApp, AppUtils.getAPPId(), new OSETInitListener() {
                @Override
                public void onError(String s) {
                    ToastUtil.showShortToast(SplashActivity.this, s);
                }

                @Override
                public void onSuccess() {//初始化成功 调用广告
                    OSETSplash.getInstance()
                            .setUserId(LoginConfig.getUserOpenId())
                            .show(SplashActivity.this, flAd, "D52FB11EB0201F52C6CDEA42FAB49047", new OSETSplashListener() {
                                @Override
                                public void onClick() {
                                    ToastUtil.showShortToast(getApplicationContext(), "点击");
                                }

                                @Override
                                public void onClose() {
                                    ToastUtil.showShortToast(getApplicationContext(), "关闭");
                                }

                                @Override
                                public void onShow() {

                                }

                                @Override
                                public void onError(String s, String s1) {
//                        ToastUtil.showShortToast(getApplicationContext(),"onError"+s1);
                                }
                            });
                }
            });
            initData();
        }
    }

    private void initData() {
        new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
            @Override
            public void run() {
                String content = SystemUtil.getClipboardContent(SplashActivity.this);
//                ToastUtil.showShortToastCenter(SplashActivity.this, "剪切板数据:" + content);
                // 从剪切板拿到邀请码
                if (content.contains("DQI")) {
                    AppConfig.INVITE_CODE = content.substring(content.indexOf("DQI"), content.indexOf("&channel"));
//                    ToastUtil.showShortToastCenter(SplashActivity.this, "邀请码：" + AppConfig.INVITE_CODE);
                }
                // 从剪切板拿到互推码
                if (content.startsWith("QAZ")) {
                    AppConfig.PUSH_CODE = content;
//                    ToastUtil.showShortToastCenter(SplashActivity.this, "互推码：" + AppConfig.PUSH_CODE);
                }
            }
        }, 1000);

        AnswerDataConfig.initAnswerData(this);//初始化题目数据源

        if (TextUtils.isEmpty(LoginConfig.getUserOpenId())) {
//            startAct();
            LoginActivity.startAct(SplashActivity.this, new LoginActivity.LoginCallBack() {
                @Override
                public void onLogin(String wxCode) {
                    AppConfig.WX_CODE = wxCode;
                    AppConfig.FROM_WX = true;

//                    DQLog.e("invite code: " + AppConfig.INVITE_CODE);
//                    checkAndRequestPermissions();
//                    initTongdunSDK();
                    Map<String, String> map = new HashMap<>();
                    map.put("code", wxCode);
                    RxhttpUtil.getInstance().get(RxhttpUtil.baseUrl + "/service/user/accessToken/", map, SplashActivity.this, new RxhttpUtil.RxHttpCallBack() {
                        @Override
                        public void onStart() {

                        }

                        @Override
                        public void onSuccess(String response) {
                            DQLog.e("RxhttpUtil==200" + response);

                            try {
                                JSONObject jsonObject = new JSONObject(response);
                                String data = jsonObject.getString("data");
                                WXLogin qaIncomeResp = new Gson().fromJson(data, WXLogin.class);
                                LoginConfig.setLoginState(true);
                                LoginConfig.setUserOpenId(qaIncomeResp.getOpenid());
                                LoginConfig.setUserId(qaIncomeResp.getUnionid());
                                LoginConfig.setUserNickName(qaIncomeResp.getNickname());
                            } catch (Exception e) {
                                throw new RuntimeException(e);
                            }


                            startActivity(new Intent(SplashActivity.this, MainActivity.class));
                            finish();
                        }

                        @Override
                        public void onError(String error) {
                            DQLog.e("RxhttpUtil==error" + error);
                            startActivity(new Intent(SplashActivity.this, MainActivity.class));
                            finish();

                        }

                        @Override
                        public void onFinish() {

                        }
                    });
                }
            });
        } else {
            finish();
            startActivity(new Intent(SplashActivity.this, MainActivity.class));
//            initTongdunSDK();
        }
    }

    private void checkAndRequestPermissions() {
        if (Build.VERSION.SDK_INT >= 23) {
            if (AppConfig.getRequestPermission()) {
                initTongdunSDK();
            } else {
                AppConfig.setRequestPermission(true);
                requestPermission1();
            }
        } else {
            initTongdunSDK();
        }
    }

    // 申请设备信息权限
    private void requestPermission1() {
//        ILog.e("requestPermission1");
        clMask.setVisibility(View.VISIBLE);
        tvTipsTitle.setText("设备权限使用说明");
        String content = getString(R.string.app_name) + "正在向您获取“设备”权限，同意后，将用于以下用途：设备适配、保障服务顺畅，并验证用户身份保障账号安全。";
        tvTipsContent.setText(content);
//
        requestPermission1.launch(Manifest.permission.READ_PHONE_STATE);
    }

    // 申请存储权限
    private void requestPermission2() {
//        new ILog().e("requestPermission2");
        tvTipsTitle.setText("存储权限使用说明");
        String content = getString(R.string.app_name) + "正在向您获取“存储”权限，同意后，将用于以下用途：实现账号、图片的缓存和使用，图片的保存与分享。";
        tvTipsContent.setText(content);

        requestPermission2.launch(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE});
    }

    private void initTongdunSDK() {
        /***/
        countDownTimer.start();
        FMAgentManger.initWithCallback(SplashActivity.this, new FMAgentManger.Callback() {
            @Override
            public void onEvent(String s) {
                countDownTimer.cancel();
                AppConfig.PARAMS = s;
                initCurrencySDK();
            }
        });
    }

    private final CountDownTimer countDownTimer = new CountDownTimer(3000L, 1000L) {
        @Override
        public void onTick(long millisUntilFinished) {
        }

        @Override
        public void onFinish() {
            FMAgentManger.needCallback = false;
            initCurrencySDK();
        }
    };

    private void initCurrencySDK() {
        // 金币系统SDK
//        HXCurrencySDK.setDebugMode(false);//默认false
//
//        if (HXCurrencySDK.isDebugMode()) {
//            AppConfig.APP_CODE = getString(R.string.APP_CODE_DEBUG);
//        }
//        DQLog.e("app code: " + AppConfig.APP_CODE);
//        DQLog.e("渠道：" + AppConfig.CH_ID);
//
//        JLUtils.setTargetPlatform(JLUtils.PLATFORM_GRO_MORE);
//
//        DQLog.e("init start");
//        CurrencyConfig config = new CurrencyConfig.Builder()
//                .appCode(AppConfig.APP_CODE)
//                .chId(AppConfig.CH_ID)
//                .cpId(AppConfig.CP_ID)
//                .chType(AppConfig.CH_TYPE_ID)
//                .params(AppConfig.PARAMS)
//                .installList(HxCommonUtil.getInstallAppList(this))
//                .runningList(HxCommonUtil.getRunningAppList(this))
//                .imageLoader(new MyImageLoader())
//                .build();
//        HXCurrencySDK.getInstance().initialize(this, config);
//
//        if (AppConfig.FROM_WX) {
//            AppConfig.FROM_WX = false;
//            HXCurrencySDK.getInstance().loginInit(2, "", "", AppConfig.WX_CODE, AppConfig.INVITE_CODE, AppConfig.PUSH_CODE, new HttpUtil.HttpUtilCallback() {
//
//                @Override
//                public void onSuccess(int i, String response) {
//                    DQLog.e("loginInit success: " + response);
//                    initCurrencySDKComplete(response);
//                }
//
//                @Override
//                public void onFailed(int i, Throwable throwable) {
//                    DQLog.e("loginInit failed: " + throwable.getMessage());
//                    initAdSDK();
//                }
//            });
//        } else {
//            HXCurrencySDK.getInstance().initData(new HttpUtil.HttpUtilCallback() {
//                @Override
//                public void onSuccess(int reqCode, String response) {
//                    DQLog.e("initData success: " + response);
//
//                    initCurrencySDKComplete(response);
//                }
//
//                @Override
//                public void onFailed(int reqCode, Throwable throwable) {
//                    DQLog.e("initData failed: " + throwable.getMessage());
//                    initAdSDK();
//                }
//            });
//        }
    }

    private boolean mIsHalfSize = false;//是否是半全屏开屏

    private void initAdSDK() {
        //step3:创建开屏广告请求参数AdSlot,具体参数含义参考文档
        DisplayMetrics dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getRealMetrics(dm);
        float splashWidthDp = UIUtils.getScreenWidthDp(this);
        int splashWidthPx = UIUtils.getScreenWidthInPx(this);
        int screenHeightPx = UIUtils.getScreenHeight(this);
        float screenHeightDp = UIUtils.px2dip(this, screenHeightPx);
        float splashHeightDp;
        int splashHeightPx;

//        ARouter.getInstance()
//                .build("/ad/csjactivity")
//                .withString("mCodeId","958162863")
//                .withBoolean("is_express",false)
//                .withBoolean("is_half_size",false)
//                .navigation();
        Intent intent = new Intent(this, CSJSplashActivity.class);
        //开屏代码位id
        intent.putExtra("splash_rit", "889377027");//可以播放
//            intent.putExtra("splash_rit", "889395331");//可以
//            intent.putExtra("splash_rit", "958162863");//激励广告
        intent.putExtra("is_express", false);
        intent.putExtra("is_half_size", false);
        startActivity(intent);


        if (mIsHalfSize) {
            // 开屏高度 = 屏幕高度 - 下方预留的高度，demo中是预留了屏幕高度的1/5，因此开屏高度传入 屏幕高度*4/5
            splashHeightDp = screenHeightDp * 4 / 5.f;
            splashHeightPx = (int) (screenHeightPx * 4 / 5.f);
        } else {
            splashHeightDp = screenHeightDp;
            splashHeightPx = screenHeightPx;
        }

        /**
         * 初始化  adset
         */


//        String pid = HXCurrencySDK.getInstance().getPid();
//
//        if (!pid.isEmpty()) {
//            DQLog.e("pid: " + pid);
//            AppConfig.CH_ID = pid;
//        }
//        // 友盟SDK初始化
//        UMManager.init(SplashActivity.this, AppConfig.UMENG_KEY, AppConfig.CH_ID);
//
//        if (keyFrom == null || !keyFrom.equals("app")) {
//            // 广告初始化
//            AdManager.getInstance().initSDK(
//                    this,
//                    AppConfig.HX_APP_ID,
//                    AppConfig.CH_ID,
//                    AppConfig.CP_ID,
//                    false,
//                    true,
//                    false);
//
////            initAppLog();
//
//            new Handler().postDelayed(new Runnable() {
//                @Override
//                public void run() {
//                    AdManager.getInstance().showSplashAD(SplashActivity.this, flAd, SplashActivity.this);
//                }
//            }, 500);
//
//            new Handler().postDelayed(new Runnable() {
//                @Override
//                public void run() {
//                    if (AppConfig.TD_BANNED == 0) {
//                        AdManager.getInstance().preloadVideoAd(SplashActivity.this);
//                    }
//                }
//            }, 1500);
//        } else {
//            startAct();
//        }
    }

//    private void initAppLog() {
//        /* 初始化开始 */
//        final InitConfig config = new InitConfig(getString(R.string.APP_LOG_ID), AdManager.channel); // appid和渠道，appid如不清楚请联系客户成功经理，注意第二个参数 channel 不能为空
//        config.setUriConfig(UriConstants.DEFAULT);//上报地址
//        // 加密开关，SDK 5.5.1 及以上版本支持，false 为关闭加密，上线前建议设置为 true
//        AppLog.setEncryptAndCompress(true);
//        config.setAutoStart(true);
//        AppLog.init(QuestionsApp.context, config);
//        /* 初始化结束 */
//    }

    private void startAct() {
        if (isStart) {
            if (keyFrom == null || !keyFrom.equals("app")) {
                startActivity(new Intent(SplashActivity.this, MainActivity.class));
            }
            finish();
            isStart = false;
        } else {
            isStart = true;
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
//        if (isStart) {
//            startAct();
//        }
        isStart = true;
    }

    @Override
    protected void onPause() {
        super.onPause();
        isStart = false;
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_HOME) {
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public Resources getResources() {
        Resources res = super.getResources();
        Configuration config = new Configuration();
        config.setToDefaults();
        res.updateConfiguration(config, res.getDisplayMetrics());
        return res;
    }

//    @Override
//    public void onNoAD(AdError adError) {
////        UMManager.onEvent(UMManager.Event.Splash_Ad_fail);
//        DQLog.e("开屏广告初始化失败了: " + adError.getErrorMsg());
//        isStart = true;
//        startAct();
//    }

//    @Override
//    public void onADPresent(AdLogInfo adLogInfo) {
//
//    }

//    @Override
//    public void onADClicked(AdLogInfo adLogInfo) {
//
//    }

//    @Override
//    public void onADSkip(AdLogInfo adLogInfo) {
//        startAct();
//    }
//
//    @Override
//    public void onADTimeOver(AdLogInfo adLogInfo) {
//        startAct();
//    }

    private void initCurrencySDKComplete(String response) {
        FastJsonUtil fastJson = new FastJsonUtil(response);

        int uste = fastJson.parsKey("uste");                //账号是否封禁 0废弃   1正常   2封禁
        int tb = fastJson.parsKey("tb");                    //同盾检测 0 关闭 1 开启
        int dm = fastJson.parsKey("dm");                    //开发者模式 0 关闭 1 开启
        AppConfig.localPermission = fastJson.parsKey("lp"); //位置权限 0关闭 1开启
        AppConfig.hasQQ = fastJson.parsKey("hq");
        AppConfig.hasQQStatus = fastJson.parsKey("hqs");

        AppConfig.TD_BANNED = fastJson.parsKey("tt");
        AppConfig.TD_BANNED_MSG = fastJson.parsingKey("tp");

        DQLog.e("dm：" + dm);
        DQLog.e("tb：" + tb);
        DQLog.e("uste：" + uste);
        if (dm == 1 && DetectionUtil.illegalDevice(SplashActivity.this)) {
            String title = "";
            if (DetectionUtil.isAdbOpen(SplashActivity.this)) {
                title = "请关闭开发者模式再试";
            } else if (!DetectionUtil.hasSimCard(SplashActivity.this)) {
                title = "请插入手机SIM卡再试";
            } else if (RootCheck.isRoot()) {
                title = "请不要打开root权限";
            } else if (EmulatorDetectUtil.isEmulator(SplashActivity.this)) {
                title = "请不要使用模拟器";
            }
            new DialogBanned(SplashActivity.this)
                    .setTitle(title)
                    .setClickLister(new DialogBanned.OnClickLister() {
                        @Override
                        public void onClose() {
                            if (SplashActivity.this.isFinishing()) {
                                return;
                            }
                            SplashActivity.this.finish();
                        }
                    }).show();
            return;
        }

        if (uste == 2 && tb == 1) {
            new DialogBanned(SplashActivity.this)
                    .setClickLister(new DialogBanned.OnClickLister() {
                        @Override
                        public void onClose() {
                            if (SplashActivity.this.isFinishing()) {
                                return;
                            }
                            SplashActivity.this.finish();
                        }
                    }).show();
            return;
        }

        int errorCode = fastJson.parsKey("errorCode");
        String errorMsg = fastJson.parsingKey("errorMessage");

        if (errorCode != 0) {
            new DialogBanned(SplashActivity.this)
                    .setTitle(errorMsg)
                    .setClickLister(new DialogBanned.OnClickLister() {
                        @Override
                        public void onClose() {
                            if (SplashActivity.this.isFinishing()) {
                                return;
                            }
                            SplashActivity.this.finish();
                        }
                    }).show();
            return;
        }

//        JLUtils.setBehaviorRecord(HXCurrencySDK.getInstance().getBehaviorRecord());

//        int type = fastJson.parsKey("type");//0游客  1用户
        int ts = fastJson.parsKey("ts");//签到状态 0未签到  1已签到
        String uid = fastJson.parsingKey("uid");
        String nn = fastJson.parsingKey("nn");
        String hiu = fastJson.parsingKey("hiu");
        String openId = fastJson.parsingKey("oi");        //OpenId

        LoginConfig.setTodaySignState(ts);
        LoginConfig.setUserId(uid);
        LoginConfig.setUserNickName(nn);
        LoginConfig.setUserHeadUrl(hiu);
        LoginConfig.setUserOpenId(openId);
        LoginConfig.setLoginState(true);

        double rat = fastJson.parsKeyDouble("rat");        //红包余额
        double bat = fastJson.parsKeyDouble("bat");        //存钱罐余额
        int ats = fastJson.parsKey("ats");                 //答题数
        int cats = fastJson.parsKey("cats");               //答对次数

        LoginConfig.setUserCash(rat);
        LoginConfig.setSaveCash(bat);
        LoginConfig.setUserAnswerNumber(ats);
        LoginConfig.setUserAnswerSuccessNumber(cats);

//        int irf = fastJson.parsKey("irf");                  //首次俸禄是否领取
//        int isAct = fastJson.parsKey("hwo");                //活动是否开启
//        int rnct = fastJson.parsKey("rnct");                    //用户碎片个数
        int earningsState = fastJson.parsKey("iss");              //用户收益分红状态
        int earningsProgress = fastJson.parsKey("ise");              //用户收益分红进度
        double earningsMoney = fastJson.parsKeyDouble("rwa");              //用户收益剩余分红金额

        LoginConfig.setUserEarningsState(earningsState);
        LoginConfig.setUserEarningsProgress(earningsProgress);
        LoginConfig.setUserEarningsMoney(earningsMoney);

        int tc = fastJson.parsKey("tc");                          //真关闭次数
//        double fcr = fastJson.parsKeyDouble("fcr");              //假关闭概率
        double rpc = fastJson.parsKeyDouble("rpc");              //红包转化

        if (!Mmkv.contains("real_close_times")) {
            LoginConfig.setRealCloseTimes(tc);
        }
        LoginConfig.setCashConvert(rpc);

        int van = fastJson.parsKey("van");                       //激励视频观看次数 1表示不能再看
        ADUtils.canShowVideoAd = (van == 0);
        int hau = fastJson.parsKey("hau");                       //是否强制更新 0关闭 1开启
        String uav = fastJson.parsingKey("uav");                 //更新包版本号
        String uas = fastJson.parsingKey("uas");                 //更新包大小
        String uau = fastJson.parsingKey("uau");                 //更新包下载地址

        AppConfig.updateInfo = new UpdateInfo();
        AppConfig.updateInfo.apkStatus = hau;
        AppConfig.updateInfo.apkVersionStr = uav;
        if (uav != null && !uav.isEmpty()) {
            AppConfig.updateInfo.apkVersion = Integer.parseInt(uav.replaceAll("[.]", ""));
        }
        if (uas != null && !uas.isEmpty()) {
            AppConfig.updateInfo.apkSize = Long.parseLong(uas);
        }
        AppConfig.updateInfo.apkUrl = uau;
        DQLog.e(AppConfig.updateInfo.toString());

        AppConfig.saveCashState = fastJson.parsKey("bs");        //存钱罐状态 0不可领取 1可领取

        AppConfig.hp = fastJson.parsKey("hp");                //体力
        AppConfig.FHP = fastJson.parsKey("fhp");              //满体力
        AppConfig.ahp = fastJson.parsKey("ahp");              //恢复1点体力所需时间
        AppConfig.UHP = fastJson.parsKey("uhp");              //恢复一点体力总时间

        String qqGroup = fastJson.parsingKey("qq");       //QQ群
        String qqGroupKey = fastJson.parsingKey("qk");         //QQ群key
        if (!qqGroup.isEmpty()) {
            AppConfig.QQ_GROUP = qqGroup;
        }
        if (!qqGroupKey.isEmpty()) {
            AppConfig.QQ_GROUP_KEY = qqGroupKey;
        }

        AnswerAdConfig.AD_INTERVAL = fastJson.parsKey("vat");                     //答题弹出广告间隔
        AnswerAdConfig.REWARD_RANDOM = fastJson.parsKeyDouble("fvar");            //激励视频概率
        AnswerAdConfig.FULLSCREEN_RANDOM = fastJson.parsKeyDouble("avar");        //全屏视频概率
        AnswerAdConfig.INTERSTITIAL_RANDOM = fastJson.parsKeyDouble("sar");       //插屏广告概率

        String mda = fastJson.parsingKey("mda");
        FastJsonUtil mdaJson = new FastJsonUtil(mda);
        String lst = mdaJson.parsingKey("lst");
        String todayLoginDate = lst.substring(0, 10);
        DQLog.e("todayLoginDate：" + todayLoginDate);
        if (!todayLoginDate.equals(LoginConfig.getLastLoginDate())) {
            LoginConfig.setSurpriseTimes(0);
            LoginConfig.setRedBubbleTimes(0);
            LoginConfig.setAddCoinTimes(0);
            LoginConfig.setLastLoginDate(todayLoginDate);
        }

        initAdSDK();
    }
}